﻿using System;
using System.Runtime.Serialization;
using FarseerPhysics.SamplesFramework;
using Flatland.GeneticProgramming.CoreTypes;
using Flatland.Labs;
using Flatland.Utilities;
using Microsoft.Xna.Framework;

namespace Flatland.GeneBank {
    /// <summary>
    /// Find food GenoType
    /// </summary>
    [Serializable]
    public class FindFood : GenoType {

        [Primitive]
        public void TurnLeft() {
            Agent.TurnLeft();
        }

        [Primitive]
        public void TurnRight() {
            Agent.TurnRight();
        }

        [Primitive]
        public void Stop() {
            Agent.Stop();
        }

        [Primitive]
        public bool SeesFood() {
            return Agent.SeesFood;
        }

        [Primitive]
        public bool Move() {
            return Agent.SeesFood;
        }
        

        [Primitive]
        public void Sniff() {
            if (Agent.SeesFood) {
                Agent.Move();
            }
            else {
                Agent.Stop();
                Agent.TurnLeft();
            }
        }

        protected override void Act(ref string msg)
        {
            Execute();
        }

        public override double Fitness()
        {
            return FoodLab.AMOUNT_OF__TEST_FOOD - Math.Abs(FoodLab.AMOUNT_OF__TEST_FOOD - Agent.FoodEaten);
        }

        public override object Clone() {
            return new FindFood();
        }

        public FindFood(SerializationInfo info, StreamingContext context) { }
        public FindFood() { }
    }
}
